package com.leoren.run.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author Leoren
 * @Date 2019/1/31 22:25
 * 正则表达式校验
 */
public class RegexUtil {

    private static String PHONE_TYPE_REGEX = "0?(13|14|15|18|17)[0-9]{9}";
    private static String USERNAME_TYPE_REGEX = "[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+";
    private static String EMAIL_TYPE_REGEX = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
    private static String PASSWORD_TYPE_REGEX = "";

    /**
     * 是否为email
     * @param str
     * @return
     */
    public static boolean ISEMAIL(String str){
        Pattern r = Pattern.compile(EMAIL_TYPE_REGEX);
        Matcher m = r.matcher(str);
        return m.matches();
    }

    /**
     * 是否为电话号码
     * @param str
     * @return
     */
    public static boolean ISPHONE (String str){
        Pattern r = Pattern.compile(PHONE_TYPE_REGEX);
        Matcher m = r.matcher(str);
        return m.matches();
    }

    /**
     * 是否是用户名
     * @param str
     * @return
     */
    public static boolean ISUSERNAME(String str){
        Pattern r = Pattern.compile(USERNAME_TYPE_REGEX);
        Matcher m = r.matcher(str);
        return m.matches();
    }



}
